﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace PonGun
{
    public class MenuScreen : Screen
    {
        List<Button> Buttons = new List<Button>();
        

        public MenuScreen(Game1 game, GSM gsm)
            : base(game, gsm)
        {
            Buttons.Add(new Button(Game, GSM, "Textures/Buttons/OnePlayer", "Textures/Buttons/OnePlayerOver", "Textures/Buttons/OnePlayerClicked") 
                { 
                    Name = "OnePlayer",
                    Position = new Vector2(Game1.RenderAreaCenter.X - 200, Game1.RenderAreaCenter.Y - 40), 
                    OnMousePointerClicked = ButtonClicked                 
                });
            Buttons.Add(new Button(Game, GSM, "Textures/Buttons/TwoPlayer", "Textures/Buttons/TwoPlayerOver", "Textures/Buttons/TwoPlayerClicked") 
                { 
                    Name = "TwoPlayer",
                    Position = new Vector2(Game1.RenderAreaCenter.X + 200, Game1.RenderAreaCenter.Y - 40), 
                    OnMousePointerClicked = ButtonClicked 
                });
            Buttons.Add(new Button(Game, GSM, "Textures/Buttons/Options", "Textures/Buttons/OptionsOver", "Textures/Buttons/OptionsClicked") 
                {
                    Name = "Options",
                    Position = new Vector2(Game1.RenderAreaCenter.X - 200, Game1.RenderAreaCenter.Y + 40), 
                    OnMousePointerClicked = ButtonClicked 
                });
            Buttons.Add(new Button(Game, GSM, "Textures/Buttons/Exit", "Textures/Buttons/ExitOver", "Textures/Buttons/ExitClicked") 
                { 
                    Name = "Exit",
                    Position = new Vector2(Game1.RenderAreaCenter.X + 200, Game1.RenderAreaCenter.Y + 40), 
                    OnMousePointerClicked = ButtonClicked 
                });
        }

        public void ButtonClicked(object sender)
        {
            if (opacity < .5f)
                return;

            switch (((Button)sender).Name)
            {
                case "Exit":
                    Game.Exit();
                    break;
                case "OnePlayer":
                    Game.Players = 1;
                    GSM.NavigateTo("GameScreen");
                    break;
                case "TwoPlayer":
                    Game.Players = 2;
                    GSM.NavigateTo("GameScreen");
                    break;
                case "Options":
                    GSM.NavigateTo("OptionsScreen");
                    break;
            }
        }

        public override void Update(GameTime gameTime)
        {

            if (Game.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
                Game.Exit();

            base.Update(gameTime);

            foreach(Button b in Buttons)
                b.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            foreach (Button b in Buttons)
                b.Draw(gameTime);
        }
    }
}